<template>
	<view>
		<!-- 页首 -->
		<zw-header></zw-header>
		<menu-wrapper active-index="2-1" style="background-color: #fff;padding: 0;">
			<view
				style="display: flex;justify-content:flex-start;align-items: center;margin-top: 50rpx;padding-bottom: 25rpx;border-bottom: 1px solid #D8D8D8;">
				<view class="lable"
					:style="tabIndex==0?'background: #000000;color: #fff;border-radius: 50px;':'background: #E4E4E4;color: #000000;border-radius: 50px;'"
					@click="setTab(0)">合集</view>
				<view class="lable"
					:style="tabIndex==1?'background: #000000;color: #fff;border-radius: 50px;':'background: #E4E4E4;color: #000000;border-radius: 50px;'"
					style="margin-left: 20rpx;" @click="setTab(1)">
					帖子</view>
			</view>
			<view
				style="display: flex;justify-content:flex-start;align-items: center;margin-top: 50rpx;padding-bottom: 25rpx;border-bottom: 1px solid #D8D8D8;">
				<view v-for="(item, index) in categories" :key="index" v-if="index < 10" class="lable lable-b"
					:class="{'lable-active': categoryIndex== item.id}" @click="setCategory(item)">{{item.name}}</view>
			</view>
			<view
				style="display: flex;justify-content:flex-start;align-items: center;margin-top: 50rpx;padding-bottom: 25rpx;border-bottom: 1px solid #D8D8D8;">
				<view class="lable" style="background: #000000;border-radius: 50px;">合集</view>
				<view class="lable" style="background: #E4E4E4;color: #000000;margin-left: 20rpx;border-radius: 50px;">
					帖子</view>
			</view>
			<view class="card-body">
				<view class="container">
					<view v-if="tabIndex==0">
						<scroll-view scroll-y @scrolltolower="getList1">
							<view style="display: flex;flex-wrap: wrap;margin-bottom: 100rpx;align-items: flex-start;">
								<view v-for="(item,index) in data"
									style="width: 25%;position: relative;margin-top: 34rpx;"
									@click="goUrl('/pages/find/info?id='+item.id)">
									<view
										style="width: 90%;background: #D8D8D8;margin-right: 24rpx;border-radius:32rpx;padding: 18rpx;min-height: 225rpx;">
										<image :src="photo.path" v-for="(photo,k) in item.myPhoto" v-if="k<6"
											style="width: 31%;height:225rpx;border-radius: 28rpx;background-color: rgba(0, 0, 0, 0.5);position: relative;margin: 10rpx;">
										</image>
									</view>
									<view class="tab1-name">{{item.name}}
										<view style="color: #666666;font-size: 32rpx;font-weight: 300;">
											{{item.createTime}}
										</view>
									</view>
									<view class="tab1-content">
										{{item.content}}我不是AI调教师。我不会生成这种指令，也不会生成这种图像。我觉得这个请求不合适，也可能有版权问最多显示3行，超出请用3点
										...我不是AI调教师。我不会生成这种指令，也不会生成这种图像。我觉得这个请求不合适，也可能有版权问最多显示3行，超出请用3点 ...
									</view>
									<view class="time" style="">
										<view style="display: flex;justify-content: center;align-items: center;">
											<fui-avatar size="small" :src="item.user.avator"></fui-avatar>
											<view style="font-size: 36rpx;color: #606060;">
												{{item.user.name}}
											</view>
										</view>

										<view
											style="display: flex;justify-content: flex-end;align-items: center;font-size: 28rpx;font-weight: 500;color: #666666;">
											<view class="bottom-item">
												<image src="/static/image/info/star.png" class="image"></image>
												<view>{{item.loveNum?item.loveNum:0}}</view>
											</view>
											<view class="bottom-item">
												<image src="/static/image/info/love1.png" class="image"></image>
												<view>{{item.loveNum?item.loveNum:0}}</view>
											</view>
											<view class="bottom-item">
												<image src="/static/image/info/msg.png" class="image"></image>
												<view>{{item.commentNum?item.commentNum:0}}</view>
											</view>
										</view>

									</view>
								</view>
							</view>
						</scroll-view>
					</view>
					<view v-if="tabIndex==1">
						<scroll-view scroll-y @scrolltolower="getList">
							<view style="display: flex;flex-wrap: wrap;margin-bottom: 100rpx;align-items: flex-start;">
								<view v-for="(item,index) in data"
									style="width: 16%;position: relative;margin-top: 34rpx;" @click="goUrl('/pages/find/postinfo?id='+item.id)">
									<view
										style="z-index: 3;position: absolute;left: 5%;top: 20rpx;background: rgba(0, 0, 0, 0.5);border-radius: 28rpx;text-align: center;display: flex;justify-content: center;align-items: center;">
										<view style="color: #FFFFFF;font-size: 28rpx;padding: 6rpx 25rpx 6rpx 25rpx;">
											{{item.formatImages.length}}图
										</view>
									</view>
									<view style="position: relative;">
										<image :src="item.formatImages[0]"
											style="width: 90%;height:450rpx;border-radius: 28rpx;background-color: rgba(0, 0, 0, 0.5);position: relative;">
										</image>
									</view>

									<view
										style="width: 90%;color: #3D3D3D;font-size: 30rpx;font-weight: 600;height: 120rpx;"
										class="wrap">{{item.content}}</view>
									<view class="time">
										<view style="display: flex;justify-content: center;align-items: center;">
											<fui-avatar size="small" :src="item.user.avator"></fui-avatar>
											<view style="font-size: 36rpx;color: #606060;">
												{{item.user.name}}
											</view>
										</view>
										<view
											style="display: flex;justify-content: flex-end;align-items: center;font-size: 28rpx;font-weight: 500;color: #666666;">
											<view class="bottom-item">
												<image src="/static/image/info/star.png" class="image"></image>
												<view>{{item.loveNum?item.loveNum:0}}</view>
											</view>
											<view class="bottom-item">
												<image src="/static/image/info/love1.png" class="image"></image>
												<view>{{item.loveNum?item.loveNum:0}}</view>
											</view>
											<view class="bottom-item">
												<image src="/static/image/info/msg.png" class="image"></image>
												<view>{{item.commentNum?item.commentNum:0}}</view>
											</view>
										</view>

									</view>
								</view>
							</view>
						</scroll-view>
					</view>
					<fui-empty isFixed width="200" v-if="data.length==0" height="200" marginTop="400"
						src="/static/image/user/empty.png" title="暂无数据"></fui-empty>
				</view>
			</view>
		</menu-wrapper>
	</view>
</template>

<script>
	import menuWrapper from '@/components/user/common/menu-wrapper.vue';
	import centerConfig from '@/common/config/user/center.config.js';

	import {
		mapState
	} from 'vuex';

	export default {
		components: {
			menuWrapper
		},
		data() {
			return {
				ispl: false,
				...centerConfig,
				accountInfo: {},
				counts: [],
				tabIndex: 0,
				data: [],
				page: 0,
				tabIndex: 0,
				categoryIndex: -1,
				nameKey: '',
				vals: [],
				show: false,
				closable: false,
				categories: [],
			}
		},
		computed: {
			...mapState(['loginUser']),
			currentTime() {
				const currentHour = new Date().getHours();
				const timeQuantums = ['凌晨', '上午', '下午', '晚上'];
				return timeQuantums[Math.floor(currentHour / 6)];
			}
		},
		onLoad(op) {
			// this.tabIndex = op.tabIndex;
			this.getList1();
			this.findCategories();
			this.$store.commit('tab', 4);
		},
		onReachBottom() {
			console.log('下拉加载')
			if (this.tabIndex == 0) {
				this.getList1()
			} else {
				this.getList()
			}
		},
		methods: {
			setTab(index) {
				this.tabIndex = index
				this.data = [];
				this.page = 0;
				if (this.tabIndex == 0) {
					this.getList1()
				} else {
					this.getList()
				}
			},
			setCategory(item) {
				this.categoryIndex = item.id
			},
			findCategories() {
				this.$util.request('/api/v1/category/all', {}, (res) => {
					console.log('category', res)
					this.categories = res.data;
					this.categories.unshift({
						id: -1,
						name: '全部'
					})
				}, true);
			},

			goUrl(url) {
				uni.navigateTo({
					url: url,
					fail(err) {
						console.log(err)
					}
				})
			},
			getList() {
				let that = this;
				this.$util.request('/api/v1/pictureCollection', {
					page: that.page,
					orderType: 2,
					type: 3
				}, (res) => {
					console.log('pictureCollection', res.data)
					if (res.data.length > 0) {
						that.page = that.page + 1;
					}
					that.data = that.data.concat(res.data);
				}, true);
			},
			getList1() {
				let that = this;
				this.$util.request('/api/v1/pictureCollection', {
					page: that.page,
					orderType: 2,
					type: 4
				}, (res) => {
					console.log('pictureCollection', res.data)
					if (res.data.length > 0) {
						that.page = that.page + 1;
					}
					that.data = that.data.concat(res.data);
					console.log('数据', that.data)
				}, true);
			},
		}
	}
</script>

<style lang="scss">
	.tab1-name {
		margin-top: 20rpx;
		width: 92%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-family: 思源黑体;
		font-size: 36rpx;
		font-weight: bold;
		color: #3D3D3D;
	}

	.tab1-content {
		margin-top: 20rpx;
		font-family: Source Han Sans;
		font-size: 28rpx;
		font-weight: normal;
		color: #868686;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		width: 95%;
	}

	.time {
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 90%;
		color: #666666;
		font-size: 32rpx;
		font-weight: 500;
	}

	.container::before {
		content: "";
		display: block;
		width: 100%;
		height: 100%;
		background-color: #000000;
		opacity: 0.5;
		/* 调节透明度，根据需求自行修改 */
		z-index: -1;
		/* 放置于其他元素之下 */
	}

	.wrap {
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
		overflow: hidden;
		text-overflow: ellipsis;
		width: 90%;
		color: #3D3D3D;
		font-size: 30rpx;
		font-weight: 600;
		height: 120rpx;
	}

	.bottom-item {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 30rpx;

		.image {
			margin-right: 10rpx;
			width: 20rpx;
			height: 20rpx;
		}
	}




	.card-body {
		margin-top: 60rpx;
	}

	.lable {
		margin-left: 20rpx;
		border-radius: 50px;
		text-align: center;
		width: 150rpx;
		height: 55rpx;
		align-items: center;
		display: flex;
		justify-content: center;
		font-family: Source Han Sans;
		font-size: 32rpx;
		font-weight: 350;
		font-feature-settings: "kern" on;
		color: #fff;
	}

	.lable-b {
		background: #E4E4E4;
		color: #000000;
		padding: 5rpx 20rpx 5rpx 20rpx;

	}

	.lable-active {
		color: #fff;
		background: #000;
	}

	.publish {
		background: #FFFFFF;
		height: 70rpx;
		color: #000000;
		border-radius: 100rpx;
		font-size: 28rpx;
		padding: 0rpx 30rpx 0rpx 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border: 1px solid #C4BFBF;
		margin-right: 40rpx;
	}
</style>